package JDBC;

import java.sql.*;
import java.util.Scanner;

public class preparedstatement {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        Scanner sc=new Scanner(System.in);

        System.out.println("请输入账号：");
        String name = sc.nextLine();
        System.out.println("请输入密码：");
        int age=sc.nextInt();

        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useSSL=false", "root", "080666");
        String sql="select *from table_name where name=? and age=?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,name);
        preparedStatement.setInt(2,age);
        ResultSet resultSet = preparedStatement.executeQuery();
        if(resultSet.next()){
            System.out.println("yes");
        }else {
            System.out.println("no");
        }

        resultSet.close();
        preparedStatement.close();
        connection.close();



    }
}
